package com.leetcode.algorithm.y22.m09.w4;

import java.util.PriorityQueue;

/**
 * 2357. 使数组中所有元素都等于零
 * 
 * https://leetcode.cn/problems/make-array-zero-by-subtracting-equal-amounts/
 * 
 * @author jie.deng
 *
 */
class Question2357Solution01 {
	
	public int minimumOperations(int[] nums) {
		int len = nums.length;
		PriorityQueue<Integer> queue = new PriorityQueue<>(len);
		for (int i = 0; i < nums.length; i++) {
			queue.offer(nums[i]);
		}
		int cnt = 0;
		int subtrahend = 0;
		while (!queue.isEmpty()) {
			int num = queue.poll().intValue();
			if (num != subtrahend) {
				subtrahend = num;
				cnt++;
			}
		}
		return cnt;
	}
	
}